package utils

import (
	"context"
	"fmt"

	"github.com/micro/go-micro/metadata"
)

//GetAgentData 获取代理商的回话信息 返回aid及error
func GetAgentData(c context.Context) (string, error) {
	md, ok := metadata.FromContext(c)
	if !ok {
		return "", fmt.Errorf("no agent data")
	}
	uid, ok := md["Aid"]
	if !ok {
		return "", fmt.Errorf("no agent data")
	}
	return uid, nil
}

//GetUserData 获取玩家信息 返回代理编号、玩家编号及error
func GetUserData(c context.Context) (string, string, error) {
	md, ok := metadata.FromContext(c)
	if !ok {
		return "", "", fmt.Errorf("no user data")
	}
	pid, ok := md["Pid"]
	if !ok {
		return "", "", fmt.Errorf("no user data")
	}

	aid, ok := md["Aid"]
	if !ok {
		return "", "", fmt.Errorf("no user data")
	}
	return aid, pid, nil
}
